'*******************************************************************************
' Name        : Tool - Code Generator For Packet Handling                      *
' Author      : Mehul                                                          *
' Start Date  : 05/03/2007                                                     *
' End Date    : 08/03/2007                                                     *
' PurPose     : It takes Main Class Id as input and generates the              *
'                       'FIX To Internal' and 'Internal To FIX' code           *
' Version     :                                                                *
' Description : It helps addition of new packets                               *
' TATA Consultancy Services? Copyright                                         *
'*******************************************************************************

Imports System.Data.OracleClient
Imports System.IO
Imports System.Math

Module modCodeGenerator

  Public mStrFilePath As String = "C:\"
  Dim gStrFileName As String
  Dim mStrFileName As String = "cls"
  Dim mIntDepth As Integer = 1
  Public mfstr As FileStream
  Public msw As StreamWriter
  Dim objScls As New clsScls
  Dim objVrbl As New clsVrbl
  Dim objMcls As New clsMainclass
  Dim objGnrtStruct As New clsGnrtStruct
  Dim gDtRef As Date = "01/01/1970 00:00:00 AM"
  Dim mBlnCallFlag As Boolean = False
  Dim mIntCallCnt As Integer = 0
  Dim mIntNoCallCnt As Integer = 0
  Dim mArrCalls() As String
  Dim mArrNoCalls() As String
  Dim mChrNoCalls() As String
  Dim mIntNoCharCallCnt As Integer = 0
  Dim mStrSubClassName As String = ""


  Private Sub mfnWriteToFile(ByVal lStrData As String _
                             , ByVal msw As StreamWriter)
    Dim lIntTabCount As Integer
    For lIntTabCount = 1 To mIntDepth
      msw.Write("  ")
    Next
    msw.WriteLine(lStrData)

  End Sub





  Public Sub gfnCodeGenerator(ByVal lIntMainClassId As Integer)


    Dim lblnFileMade, lblnFunctionGenerated, lblnCodeGenerated As Boolean

    lblnFileMade = lfnCreateFile(lIntMainClassId)

    objScls.mIntSubClassMclsId = lIntMainClassId
    objScls.fnSelectSclsBasdMcls()

    While objScls.mDrSubClass.Read()

      lblnFunctionGenerated = lfnWriteFunctionI2F()

      objVrbl.mIntVrblSclsIdxx = objScls.mDrSubClass(0).ToString
      objVrbl.mIntVrblMclsIdxx = lIntMainClassId

      objVrbl.fnSelectVrblBasdMclsScls()

      While objVrbl.mDrVrbl.Read()
        lblnCodeGenerated = lfnWriteCodeI2F()
      End While

      objVrbl.mDrVrbl.Close()

      lfnCloseFileI2F()

    End While

    objScls.mDrSubClass.Close()

    'FIX 2 INTERNAL

    objScls.mIntSubClassMclsId = lIntMainClassId
    objScls.fnSelectSclsBasdMcls()

    While objScls.mDrSubClass.Read()

      lblnFunctionGenerated = lfnWriteFunctionF2I()

      objVrbl.mIntVrblSclsIdxx = objScls.mDrSubClass(0).ToString
      objVrbl.mIntVrblMclsIdxx = lIntMainClassId

      ''Ariz 
      objVrbl.fnSelectVrblBasdMclsScls()

      While objVrbl.mDrVrbl.Read()
        lblnCodeGenerated = mFnWriteReDimCndtn()
      End While

      objVrbl.mDrVrbl.Close()

      ''Ariz
      objVrbl.fnSelectVrblBasdMclsScls()

      While objVrbl.mDrVrbl.Read()
        lblnCodeGenerated = lfnWriteCodeF2I()
      End While

      objVrbl.mDrVrbl.Close()

      lfnCloseFileF2I()


    End While

    mfstr = New FileStream(gStrFileName, FileMode.Append)
    msw = New StreamWriter(mfstr)
    mfnWriteToFile("  End Class", msw)
    mfnWriteToFile("End Namespace", msw)
    msw.Close()
    mfstr.Close()
    msw = Nothing
    mfstr = Nothing

    objScls.mDrSubClass.Close()
    gStrFileName = ""
    mStrFileName = "cls"
    mIntDepth = 1

    DBDisconnect()

  End Sub





  Private Function lfnCreateFile(ByVal lIntMainClsId As Integer) As Boolean

    Try
      Dim MaxComntDecltn As Integer = 16
      Dim larrComntDecltn(MaxComntDecltn)
      Dim lIntcount As Integer
      Dim lStrSQL As String = ""


      objMcls.mIntMainClassId = lIntMainClsId
      objMcls.SelectMclsNameBasdIdxx()

      While objMcls.mDrMainClass.Read()
        mStrFileName += Trim(objMcls.mDrMainClass("MCLS_NAME").ToString)
      End While

      If Directory.Exists("C:\WriteSet") Then
        Directory.CreateDirectory("C:\Writeset")
      End If
      gStrFileName = mStrFilePath & "WriteSet\" + mStrFileName + "WriteSet"
      gStrFileName += ".vb"

      mfstr = New FileStream(gStrFileName, FileMode.Create)
      msw = New StreamWriter(mfstr)

      larrComntDecltn(0) = "'***************************************" _
                          + "****************************************"
      larrComntDecltn(1) = "' Name        : Packet handling Codes for" _
                          + " the Main Class : " + mStrFileName
      larrComntDecltn(2) = "' Author      : Generated Code by  Tool - " _
                          + "Code Generator For Packet Handling   *"
      larrComntDecltn(3) = "' Date        :                           " _
                          + "                                     *"
      larrComntDecltn(4) = "' PurPose     : Has function to set the field" _
                          + "when packet comes and            *"
      larrComntDecltn(5) = "'                       fill the string which " _
                          + "goes as a packet                 *"
      larrComntDecltn(6) = "' Version     :                               " _
                          + "                                 *"
      larrComntDecltn(7) = "' Description : It has functions called when " _
                          + "packets are handled               *"
      larrComntDecltn(8) = "' TATA Consultancy Services?Copyright       " _
                          + "                                  *"
      larrComntDecltn(9) = "'***************************************" _
                          + "****************************************"
      larrComntDecltn(10) = "Imports System.Runtime.InteropServices"
      larrComntDecltn(11) = "Namespace WriteSetFieldsClasses"
      larrComntDecltn(12) = "  Public Class " + mStrFileName + "WriteSet"
      larrComntDecltn(13) = "    Dim mChrDel As Char = ChrW(1)"
      larrComntDecltn(14) = "    Dim objOtherFixFunc As clsOtherFixFunc"
      larrComntDecltn(15) = ""
      larrComntDecltn(16) = ""

      For lIntcount = 0 To MaxComntDecltn
        mfnWriteToFile(larrComntDecltn(lIntcount), msw)
      Next
      mIntDepth += 2

      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing

      Return True
    Catch excp As Exception
      Return False
      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing
    End Try

  End Function





  Private Function lfnWriteFunctionI2F() As Boolean

    Try
      Dim MaxDeclarations As Integer = 6
      Dim lIntcount As Integer
      Dim lStrFunctName As String
      Dim larrDeclaration(MaxDeclarations) As String
      Dim lIntExt As Integer


      mfstr = New FileStream(gStrFileName, FileMode.Append)
      msw = New StreamWriter(mfstr)

      lIntExt = gStrFileName.IndexOf(".")
            lStrFunctName = "Public Function Write" _
                        + Trim(objScls.mDrSubClass(1).ToString) _
                        + "Field (ByVal aBytStructPacket As object _"
            'changed by prasad-- from Byte() to object
      mfnWriteToFile(lStrFunctName, msw)
      lStrFunctName = "                               " _
                      + ", ByRef aStrFixMesg As String) As Boolean"
      mfnWriteToFile(lStrFunctName, msw)

      larrDeclaration(0) = "Dim lStrEachTag As String"
      larrDeclaration(1) = "Dim obj" + Trim(objScls.mDrSubClass(1).ToString) _
                          + " As New CommsGlobalStructures." + Trim(mStrFileName) + ".cls" _
                          + Trim(objScls.mDrSubClass(1).ToString)
      larrDeclaration(2) = "Dim lBlnVal As Boolean"
      larrDeclaration(3) = "Dim lIntCount As Integer = 0"
      'added by Prasad
      larrDeclaration(4) = "obj" + Trim(objScls.mDrSubClass(1).ToString) _
                            + "= aBytStructPacket"
      larrDeclaration(5) = ""
      larrDeclaration(6) = ""
      'Commented by Prasad
      'larrDeclaration(4) = "Dim Ptr As IntPtr = Marshal.AllocHGlobal" _
      '                    + "(Marshal.SizeOf(obj" _
      '                    + Trim(objScls.mDrSubClass(1).ToString) + "))"
      'larrDeclaration(5) = "Marshal.Copy(aBytStructPacket, 0, Ptr, Marshal." _
      '                    + "SizeOf(obj" + Trim(objScls.mDrSubClass(1).ToString) + "))"
      'larrDeclaration(6) = "Marshal.PtrToStructure(Ptr, obj" + _
      '                    Trim(objScls.mDrSubClass(1).ToString) + ")"
      

      mIntDepth += 1
      For lIntcount = 0 To MaxDeclarations
        mfnWriteToFile(larrDeclaration(lIntcount), msw)
      Next

      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing
      Return True
    Catch excp As Exception
      Return False
      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing
    End Try

  End Function





  Private Function lfnWriteCodeI2F() As Boolean

    Try
      Dim lStrCondition, lStrLocalStrLine2, lStrObjLine, lStrPrefix As String
      Dim lStrLocalStrLine As String = "lBlnVal = "
      mfstr = New FileStream(gStrFileName, FileMode.Append)
      msw = New StreamWriter(mfstr)

      lStrLocalStrLine2 = "              "

      If Not ((objVrbl.mDrVrbl(2).ToString.ToLower.Contains("filler")) Or _
            (Trim(objVrbl.mDrVrbl(10).ToString).ToLower).Contains("not defined")) Then
        If (Trim(objVrbl.mDrVrbl(5).ToString).ToLower).Contains("user defined") Then
          If Not (objVrbl.mDrVrbl(9).ToString.ToLower.Contains _
                          (mStrFileName.Substring(3).ToLower)) And _
                          objVrbl.mDrVrbl(2).ToString.ToLower.Contains("execinst") = False  Then
            lStrObjLine = "Dim lObj" + Trim(objVrbl.mDrVrbl(2).ToString) _
                        + " As New cls" + Trim(Left(objVrbl.mDrVrbl(9).ToString, _
                        (InStr(objVrbl.mDrVrbl(9).ToString, ".") - 1)))
            lStrObjLine += "WriteSet"
            mfnWriteToFile(lStrObjLine, msw)
            lStrLocalStrLine += "lObj" + Trim(objVrbl.mDrVrbl(2).ToString) + "."
          End If
          If objVrbl.mDrVrbl(2).ToString.ToLower.Contains("execinst") = True Then

            lStrLocalStrLine = ""
            lStrLocalStrLine = "objOtherFixFunc.writeExecInst(obj" & _
                               Trim(objScls.mDrSubClass(1).ToString) & ".mObjExecInst, aStrFixMesg)"

          Else

            lStrLocalStrLine += "Write" + Right(objVrbl.mDrVrbl(9).ToString, _
                        (objVrbl.mDrVrbl(9).ToString.Length - InStr(objVrbl.mDrVrbl(9) _
                        .ToString, ".cls") - 3)) _
                        + "Field (obj" + Trim(objScls.mDrSubClass(1).ToString) + ".mObj" & objVrbl.mDrVrbl(2) & ", aStrFixMesg)"

            '+ "Field (obj" + Trim(objScls.mDrSubClass(1).ToString) + ".mObjHeader, aStrFixMesg)"
            'modified by Prasad
          End If
          mfnWriteToFile(lStrLocalStrLine, msw)
          mfnWriteToFile("", msw)
          mBlnCallFlag = True
        Else
          lStrPrefix = objGnrtStruct.fnPassVarPrefix(objVrbl.mDrVrbl(5).ToString _
                                                   , objVrbl.mDrVrbl(7).ToString)

          'If Trim(objVrbl.mDrVrbl(5).ToString).ToLower = "char" Then
          If lStrPrefix = "mArrChr" Then
            lStrCondition = "lBlnVal = objOtherFixFunc.CheckArray(obj" + Trim(objScls.mDrSubClass(1).ToString) _
                              + ".prp" + lStrPrefix.Substring(1) + objVrbl.mDrVrbl(2) + ")"

            mfnWriteToFile(lStrCondition, msw)

          Else

            lStrCondition = ""

            lStrCondition = "If (obj" + Trim(objScls.mDrSubClass(1).ToString) _
                            + ".prp" + lStrPrefix.Substring(1) + objVrbl.mDrVrbl(2)

            lStrCondition += " <> "

          End If


          'If Trim(objVrbl.mDrVrbl(5).ToString).ToLower = "char" Then
          '  lStrCondition += "(0)"
          'End If



          If (Trim(objVrbl.mDrVrbl(5).ToString).ToLower = "byte" Or _
              Trim(objVrbl.mDrVrbl(5).ToString).ToLower = "boolean" Or _
              Trim(objVrbl.mDrVrbl(5).ToString).ToLower = "char") Then

            'If Trim(objVrbl.mDrVrbl(5).ToString).ToLower = "char" Then
            If lStrPrefix = "mArrChr" Then
              lStrCondition = ""

              'lStrCondition += "Microsoft.VisualBasic.vbNullChar And  lStrLocal <> " + Chr(34) + Chr(34)

              lStrCondition += "If lBlnVal = True Then "
              mfnWriteToFile(lStrCondition, msw)
              lStrCondition = ""
            Else
              lStrCondition += Chr(34) + Chr(34)
              lStrCondition += ") And (obj" + Trim(objScls.mDrSubClass(1).ToString) _
                                            + ".prp" + lStrPrefix.Substring(1) + objVrbl.mDrVrbl(2) _
                                            + " <> Nothing"
              lStrCondition += ") Then"
            End If


            'Added by Prasad

          Else
            lStrCondition += "0"
            lStrCondition += ") Then"
          End If


          mfnWriteToFile(lStrCondition, msw)
          If (Right(Trim(objVrbl.mDrVrbl(10).ToString), 4).ToLower = "time") Then
            lStrLocalStrLine = "lStrEachTag = objOtherFixFunc.MillisToUTCTS(obj" _
                        + Trim(objScls.mDrSubClass(1).ToString) + ".prp" _
                        + lStrPrefix.Substring(1) + objVrbl.mDrVrbl(2) + "())"
          Else

            'replaced + with & by Prasad
            lStrLocalStrLine = "lStrEachTag = Cstr(modFields.enumFixTagValues." + _
                            objVrbl.mDrVrbl(10).ToString + ") & " + _
                            Chr(34) + "=" + Chr(34) + " &  _"

            If (Trim(objVrbl.mDrVrbl(5).ToString).ToLower = "string" Or _
                Trim(objVrbl.mDrVrbl(5).ToString).ToLower = "boolean" Or _
                Trim(objVrbl.mDrVrbl(5).ToString).ToLower = "char") Then
              lStrLocalStrLine2 += "obj" + Trim(objScls.mDrSubClass(1).ToString) _
                                  + ".prp" + lStrPrefix.Substring(1) + objVrbl.mDrVrbl(2) _
                                  + "() + mChrDel"


            Else
              lStrLocalStrLine2 += "Cstr(obj" + Trim(objScls.mDrSubClass(1).ToString) _
                               + ".prp" + lStrPrefix.Substring(1) + objVrbl.mDrVrbl(2) _
                               + "()) + mChrDel"
            End If

          End If
          mIntDepth += 1
          mfnWriteToFile(lStrLocalStrLine, msw)
          mfnWriteToFile(lStrLocalStrLine2, msw)
          mfnWriteToFile("aStrFixMesg = aStrFixMesg + lStrEachTag", msw)
          mIntDepth -= 1
          'If Trim(objVrbl.mDrVrbl(5).ToString).ToLower = "char" Then
          '  mfnWriteToFile("End If", msw)
          'End If

          mfnWriteToFile("End If", msw)
          mfnWriteToFile("", msw)
        End If
      End If

      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing
      Return True
    Catch excp As Exception
      Return False
      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing
    End Try

  End Function





  Private Function lfnCloseFileI2F()
    Dim lIntcount As Integer
    Try

   
      If Directory.Exists("C:\WriteSet") = False Then
        Directory.CreateDirectory("C:\Writeset")
      End If

      mfstr = New FileStream(gStrFileName, FileMode.Append)
      msw = New StreamWriter(mfstr)
      If mBlnCallFlag = True Then
        mfnWriteToFile("If lBlnVal = False Then", msw)
        mIntDepth += 1
        mfnWriteToFile("Return False", msw)
        mIntDepth -= 1
        mfnWriteToFile("Else", msw)
        mIntDepth += 1
        mfnWriteToFile("Return True", msw)
        mIntDepth -= 1
        mfnWriteToFile("End If", msw)
      Else
        mfnWriteToFile("Return True", msw)
      End If
      mIntDepth -= 1
      mfnWriteToFile("", msw)
      mfnWriteToFile("End Function", msw)

      For lIntcount = 1 To 5
        mfnWriteToFile("", msw)
      Next

      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing

    Catch ex As Exception
      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing
    End Try
  End Function





  Private Function lfnWriteFunctionF2I() As Boolean

    Try
      Dim lStrFunctName As String
      Dim lIntExt As Integer


      mfstr = New FileStream(gStrFileName, FileMode.Append)
      msw = New StreamWriter(mfstr)

      lIntExt = gStrFileName.IndexOf(".")
      lStrFunctName = "Public Function Set" + Trim(objScls.mDrSubClass(1).ToString) _
                  + "Field (ByRef aArrStrBody() As String _"
      mfnWriteToFile(lStrFunctName, msw)
      lStrFunctName = "                             " _
                      + ", ByRef aRecvObj " + "As Object) As Boolean"
      mfnWriteToFile(lStrFunctName, msw)
      mIntDepth += 1
      mfnWriteToFile("Dim lBlnVal As Boolean", msw)
      mfnWriteToFile("Dim obj" + Trim(objScls.mDrSubClass(1).ToString) _
                          + " As New CommsGlobalStructures." + Trim(mStrFileName) + ".cls" _
                          + Trim(objScls.mDrSubClass(1).ToString), msw)

      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing
      Return True
    Catch excp As Exception
      Return False
      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing
    End Try

  End Function





  Private Function lfnWriteCodeF2I() As Boolean


    Try
      Dim lStrCondition As String = ""
      Dim lStrCopyLine As String = ""
      Dim lStrPrefix As String
      Dim lStrPrptyName As String = ""
      Dim lStrCopyCharLine As String = ""

      mfstr = New FileStream(gStrFileName, FileMode.Append)
      msw = New StreamWriter(mfstr)
      mIntDepth += 5
      lStrPrefix = objGnrtStruct.fnPassVarPrefix(objVrbl.mDrVrbl(5).ToString _
                                         , objVrbl.mDrVrbl(7).ToString)



      If (Not (Trim(objVrbl.mDrVrbl(2).ToString).ToLower.Contains("filler") Or _
           (Trim(objVrbl.mDrVrbl(10).ToString).ToLower).Contains("not defined"))) Then
        'If (Trim(objVrbl.mDrVrbl(5).ToString).ToLower).Contains("user defined") Then
        If (Trim(objVrbl.mDrVrbl(5).ToString).ToLower).Contains("user defined") And _
           Trim(objVrbl.mDrVrbl(2).ToString).ToLower.Contains("execinst") = False Then
          mIntCallCnt += 1
          ReDim Preserve mArrCalls(mIntCallCnt + 1)
          mArrCalls(mIntCallCnt) = "Dim lObj" + Trim(objVrbl.mDrVrbl(2).ToString) _
                      + " As New cls" + Trim(Left(objVrbl.mDrVrbl(9).ToString, _
                      (InStr(objVrbl.mDrVrbl(9).ToString, ".") - 1))) + "WriteSet"
          mIntCallCnt += 1
          mArrCalls(mIntCallCnt) = "lBlnVal =" + "lObj" + Trim(objVrbl.mDrVrbl(2) _
                      .ToString) + "." + "Set" + Right(objVrbl.mDrVrbl(9).ToString, _
                      (objVrbl.mDrVrbl(9).ToString.Length - InStr(objVrbl.mDrVrbl(9) _
                      .ToString, ".cls") - 3)) + "Field (aArrStrBody, obj" + Trim(objScls _
                      .mDrSubClass(1).ToString) + ".mObj" + Trim(objVrbl.mDrVrbl(2) _
                      .ToString) + ")"

          'mArrCalls(mIntCallCnt) = lStrCopyCharLine
          'mIntCallCnt += 1
          'mArrCalls(mIntCallCnt) = ""

        Else
          mIntNoCallCnt += 1
          ReDim Preserve mArrNoCalls(mIntNoCallCnt + 4)
          If Trim(objVrbl.mDrVrbl(2).ToString).ToLower = "execinst" Then
            lStrCondition = "Case modFields.enumFixTagValues.ExecInst"
          Else
            lStrCondition = "Case modFields.enumFixTagValues." + objVrbl.mDrVrbl(10)
          End If

          mArrNoCalls(mIntNoCallCnt) = lStrCondition
          mIntNoCallCnt += 1
          If (Right(Trim(objVrbl.mDrVrbl(10).ToString), 4).ToLower = "time") Then
            lStrCopyLine = "  obj" + Trim(objScls.mDrSubClass(1).ToString) + ".prp" _
                        + lStrPrefix.Substring(1) + objVrbl.mDrVrbl(2) _
                        + " = objOtherFixFunc.UTCTSToMillis(lArrStrValue(1))"
          Else

            lStrPrefix = objGnrtStruct.fnPassVarPrefix(objVrbl.mDrVrbl(5).ToString _
                                                     , objVrbl.mDrVrbl(7).ToString)
            lStrCopyLine = ""

            lStrPrptyName = ""

            lStrPrptyName = "obj" + Trim(objScls.mDrSubClass(1).ToString) _
                          + ".prp" + lStrPrefix.Substring(1) + objVrbl.mDrVrbl(2)

            If Trim(objVrbl.mDrVrbl(2).ToString).ToLower = "execinst" Then

              lStrCopyLine = "objOtherFixFunc.setExecInst(obj" + Trim(objScls _
                      .mDrSubClass(1).ToString) + ".mObj" + Trim(objVrbl.mDrVrbl(2) _
                      .ToString) + ", lArrStrValue(1))"


            End If


            If lStrPrefix = "mArrChr" Then

              lStrCopyLine = "objOtherFixFunc.strnfill(lArrStrValue(1), " & Trim(objVrbl.mDrVrbl(8)) & ")" + vbCrLf

              lStrCopyLine += "                  "

            ElseIf lStrPrefix = "mChr" Then
              If mStrSubClassName <> Trim(objScls.mDrSubClass(1).ToString) Then
                mIntNoCharCallCnt = 0
                mStrSubClassName = Trim(objScls.mDrSubClass(1).ToString)
              End If

              mIntNoCharCallCnt += 1
              ReDim Preserve mChrNoCalls(mIntNoCharCallCnt + 4)
              lStrCopyCharLine = "objOtherFixFunc.strnFillChar(" & Trim(lStrPrptyName) & ")"
              mChrNoCalls(mIntNoCharCallCnt) = lStrCopyCharLine
              mIntNoCharCallCnt += 1
              mChrNoCalls(mIntNoCharCallCnt) = ""

            End If
            If Trim(objVrbl.mDrVrbl(2).ToString).ToLower.Contains("execinst") = False Then

              lStrCopyLine += lStrPrptyName + "() = lArrStrValue(1)"
            End If
         
            End If

            mArrNoCalls(mIntNoCallCnt) = lStrCopyLine
            mIntNoCallCnt += 1
            mArrNoCalls(mIntNoCallCnt) = "Exit Select"
            mIntNoCallCnt += 1
            mArrNoCalls(mIntNoCallCnt) = ""
            mIntNoCallCnt += 1
        End If
      End If
      mIntDepth -= 5

      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing
      Return True
    Catch excp As Exception
      MsgBox(excp.ToString)
      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing
      Return False
    End Try

  End Function





  Private Sub lfnCloseFileF2I()
    Try

    
      Dim lIntCnt As Integer = 0
      Dim MaxDeclarations As Integer = 8
      Dim lIntcount As Integer
      Dim larrDeclaration(MaxDeclarations) As String
      mfstr = New FileStream(gStrFileName, FileMode.Append)
      msw = New StreamWriter(mfstr)
      If mIntNoCallCnt > 0 Then
        larrDeclaration(0) = "Dim lArrStrFixBody() As String = aArrStrBody"
        larrDeclaration(1) = ""
        larrDeclaration(2) = "For Each str As String In lArrStrFixBody"
        larrDeclaration(3) = "  Try"
        larrDeclaration(4) = "    If str.Trim.Length > 0 Then"
        larrDeclaration(5) = "      Dim lArrStrValue() As String = str.Split(" _
                                            + Chr(34) + "=" + Chr(34) + ")"
        larrDeclaration(6) = "      If Trim(lArrStrValue(0)) <> " + Chr(34) + Chr(34) _
                                            + " Then"
        larrDeclaration(7) = "        Select Case (lArrStrValue(0))"
        larrDeclaration(8) = ""

        For lIntcount = 0 To MaxDeclarations
          mfnWriteToFile(larrDeclaration(lIntcount), msw)
        Next

        mIntDepth += 5
        For lIntCnt = 1 To mIntNoCallCnt
          mfnWriteToFile(mArrNoCalls(lIntCnt), msw)
        Next
        mIntDepth -= 5
        mIntNoCallCnt = 0

        mfnWriteToFile("          Case Else", msw)
        'added by Prasad
        mfnWriteToFile("            Exit Select", msw)
        'commented by Prasad
        'mfnWriteToFile("            Return False", msw)
        mfnWriteToFile("        End Select", msw)
        mfnWriteToFile("      End If", msw)
        mfnWriteToFile("    End If", msw)
        mfnWriteToFile("  Catch excp As Exception", msw)
        mIntDepth += 2
        mfnWriteToFile("Return False", msw)
        mIntDepth -= 2
        mfnWriteToFile("  End Try", msw)
        mfnWriteToFile("Next", msw)
      End If

      If mIntNoCharCallCnt > 0 Then
        lIntCnt = 0
        For lIntCnt = 1 To mIntNoCharCallCnt
          mfnWriteToFile(mChrNoCalls(lIntCnt), msw)
        Next
        mIntNoCharCallCnt = 0
      End If

      If mIntCallCnt > 0 Then
        lIntCnt = 0
        For lIntCnt = 1 To mIntCallCnt
          mfnWriteToFile(mArrCalls(lIntCnt), msw)
        Next
        mIntCallCnt = 0
      End If


      mfnWriteToFile("aRecvObj = obj" + Trim(objScls.mDrSubClass(1).ToString), msw)
      mfnWriteToFile("Return True", msw)
      mIntDepth -= 1
      mfnWriteToFile("", msw)
      mfnWriteToFile("End Function", msw)
      mfnWriteToFile("", msw)
      mfnWriteToFile("", msw)
      mfnWriteToFile("", msw)
      mfnWriteToFile("", msw)
      mfnWriteToFile("", msw)

      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing

    Catch ex As Exception
      msw.Close()
      mfstr.Close()
      msw.Dispose()
      mfstr.Dispose()
      msw = Nothing
      mfstr = Nothing
    End Try

  End Sub





  Public Function MillisToUTCTS(ByVal aDblDiff As Double) As String
    Dim rStrUTCTS As String
    Dim lDblTimeInSec As Double
    Dim ldblRemndr As Double
    Dim lDtGotDate As Date


    lDblTimeInSec = aDblDiff / 1000
    lDblTimeInSec = Truncate(lDblTimeInSec)
    ldblRemndr = aDblDiff - (lDblTimeInSec * 1000)
    lDtGotDate = DateAdd(DateInterval.Second, lDblTimeInSec, gDtRef)
    rStrUTCTS = Format(lDtGotDate, "yyyyMMdd-hh:mm:ss") + "." + _
                    CStr(Truncate(ldblRemndr))
    Return rStrUTCTS

  End Function





  Public Function UTCTSToMillis(ByVal aDtGotString As String) As Double
    Dim rDblDiff As Double
    Dim lStrTemDate As String
    Dim lDtGotDate As Date
    lStrTemDate = Left(aDtGotString, (InStr(aDtGotString, ".") - 1))
    lDtGotDate = Date.ParseExact(lStrTemDate, "yyyyMMdd-hh:mm:ss", _
                    System.Globalization.DateTimeFormatInfo.InvariantInfo)
    rDblDiff = lDtGotDate.Subtract(gDtRef).TotalMilliseconds
    Return rDblDiff

  End Function


  Private Function mFnWriteReDimCndtn() As Boolean

    Dim lStrCondition As String = ""
    Dim lStrCopyLine As String = ""
    Dim lStrPrefix As String
    Dim lStrPrptyName As String = ""

    mfstr = New FileStream(gStrFileName, FileMode.Append)
    msw = New StreamWriter(mfstr)

    lStrPrefix = objGnrtStruct.fnPassVarPrefix(objVrbl.mDrVrbl(5).ToString _
                                       , objVrbl.mDrVrbl(7).ToString)

    If lStrPrefix = "mArrChr" Then
      lStrPrptyName = Trim(objScls.mDrSubClass(1).ToString) _
                                        + ".prp" + lStrPrefix.Substring(1) + objVrbl.mDrVrbl(2)

      lStrCopyLine = "ReDim Preserve obj" + lStrPrptyName + "(" _
                                  + Trim(objVrbl.mDrVrbl(8)) + ")"
      mfnWriteToFile(lStrCopyLine, msw)

      lStrCopyLine = ""
      lStrCopyLine = "objOtherFixFunc.strnfill(Obj" & lStrPrptyName & "," & Trim(objVrbl.mDrVrbl(8)) + ")" + vbCrLf

      mfnWriteToFile(lStrCopyLine, msw)

    End If
    msw.Close()
    mfstr.Close()
    msw.Dispose()
    mfstr.Dispose()
    msw = Nothing
    mfstr = Nothing
  End Function


  Private Function mFnFillChrField() As Boolean

    Dim lStrCondition As String = ""
    Dim lStrCopyLine As String = ""
    Dim lStrPrefix As String
    Dim lStrPrptyName As String = ""

    mfstr = New FileStream(gStrFileName, FileMode.Append)
    msw = New StreamWriter(mfstr)

    lStrPrefix = objGnrtStruct.fnPassVarPrefix(objVrbl.mDrVrbl(5).ToString _
                                       , objVrbl.mDrVrbl(7).ToString)

    If lStrPrefix = "mChr" Then
      lStrPrptyName = Trim(objScls.mDrSubClass(1).ToString) _
                                        + ".prp" + lStrPrefix.Substring(1) + objVrbl.mDrVrbl(2)

      lStrCopyLine = ""
      lStrCopyLine = "objOtherFixFunc.strnFillChar(" & lStrPrptyName & ")"
      mfnWriteToFile(lStrCopyLine, msw)

    End If
    msw.Close()
    mfstr.Close()
    msw.Dispose()
    mfstr.Dispose()
    msw = Nothing
    mfstr = Nothing
  End Function

End Module
